﻿using System;
using System.Text.RegularExpressions;

namespace OurCouse.WebApp.Ctrls
{
	/// <summary>
	/// 用户登录控件
	/// </summary>
	public partial class LoginCtrl : System.Web.UI.UserControl
	{
		/// <summary>
		/// 登录事件句柄
		/// </summary>
		private event EventHandler _loginEvent = null;

		/// <summary>
		/// 控件加载函数
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected void Page_Load(object sender, EventArgs e)
		{
			this._btnLogin.Click += new EventHandler(this._btnLogin_Click);
		}

		/// <summary>
		/// 添加或移除登录事件
		/// </summary>
		public event EventHandler LoginEvent
		{
			add
			{
				this._loginEvent += value;
			}

			remove
			{
				this._loginEvent -= value;
			}
		}

		/// <summary>
		/// 获取用户名称
		/// </summary>
		public string UserName
		{
			get
			{
				return this._txtUserName.Text;
			}
		}

		/// <summary>
		/// 获取用户密码
		/// </summary>
		public string UserPass
		{
			get
			{
				return this._txtUserPass.Text;
			}
		}

		/// <summary>
		/// 登录按钮点击事件函数
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void _btnLogin_Click(object sender, EventArgs e)
		{
			this.OnLogin(e);
		}

		/// <summary>
		/// 登录触发函数
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnLogin(EventArgs e)
		{
			if (this._loginEvent != null)
			{
				this._loginEvent(this, e);
			}
		}
	}
}